package com.moon.interface_api.response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *Created by chengliang on 2018/11/1.
 */
public class Result {
    /** 业务处理返回编码，0000表示成功，其他表示失败 */
    private String code = "0000";
    private String status = STATUS_SUCCESS;
    private String memo = "操作成功";
    private Object result;
    private List<? extends Object> results = new ArrayList<Object>();
    private Map<? extends Object, ? extends Object> resultMap = new HashMap<Object, Object>();
    private long total;
    private long amount;
    public static final String STATUS_SUCCESS = "SUCCESS";
    public static final String STATUS_FAILD = "FAILD";


    /**
     * 获取失败结果
     * @param code
     * @param memo
     */
    public static Result error(String code, String memo) {
        Result model = new Result();
        model.setCode(code);
        model.setMemo(memo);
        model.setStatus(STATUS_FAILD);
        return model;
    }

    public static Result error() {
        Result model = new Result();
        model.setCode("1111");
        model.setMemo("操作失败");
        model.setStatus(STATUS_FAILD);
        return model;
    }

    /**
     * 返回成功结果
     */
    public static Result success(List<? extends Object> results,Map<? extends Object, ? extends Object> resultMap,Object result,long total ) {
        Result model = new Result();
        model.setResults(results);
        model.setResultMap(resultMap);
        model.setResult(result);
        model.setTotal(total);
        return model;
    }
    /**
     * 返回成功结果
     */
    public static Result success(List<? extends Object> results,Map<? extends Object, ? extends Object> resultMap ) {
        Result model = new Result();
        model.setResults(results);
        model.setResultMap(resultMap);
        return model;
    }

    /**
     * 返回成功结果
     */
    public static Result success(List<? extends Object> results ) {
        Result model = new Result();
        model.setResults(results);
        return model;
    }

    /**
     * 返回成功结果
     */
    public static Result success(Map<? extends Object, ? extends Object> resultMap ) {
        Result model = new Result();
        model.setResultMap(resultMap);
        return model;
    }
    /**
     * 返回成功结果
     */
    public static Result success(Object result ) {
        Result model = new Result();
        model.setResult(result);
        return model;
    }
    /**
     * 返回成功结果
     */
    public static Result success(String code,String memo ) {
        Result model = new Result();
        model.setCode(code);
        model.setMemo(memo);
        return model;
    }
    /**
     * 返回成功结果
     */
    public static Result success() {
        Result model = new Result();
        return model;
    }

    public String getCode() {
        return code;
    }

    public String getMemo() {
        return memo;
    }


    public void setCode(String code) {
        this.code = code;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }


    public Result() {
        super();
    }

    public Object getResult() {
        return result;
    }

    public List<? extends Object> getResults() {
        return results;
    }

    public Map<? extends Object, ? extends Object> getResultMap() {
        return resultMap;
    }

    public long getTotal() {
        return total;
    }


    public void setResult(Object result) {
        this.result = result;
    }

    public void setResults(List<? extends Object> results) {
        this.results = results;
    }

    public void setResultMap(Map<? extends Object, ? extends Object> resultMap) {
        this.resultMap = resultMap;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public Result(String status, String code, String memo) {
        super();
        this.status = status;
        this.code = code;
        this.memo = memo;
    }

    public Result(String memo) {
        super();
        this.memo = memo;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public long getAmount() {
        return amount;
    }

    public void setAmount(long amount) {
        this.amount = amount;
    }

    @Override
    public String toString() {
        return "Result [code=" + code + ", status=" + status + ", memo=" + memo + ", result=" + result + ", results=" + results + ", resultMap=" + resultMap + ", total=" + total + ", amount=" + amount + "]";
    }

}
